package tag27_18_08.streams;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class St08_BufferedReaderBufferedWriter {

	public static void main(String[] args) throws IOException {

		PrintWriter tmp = new PrintWriter("test4.txt");

		for (int i = 0; i < 10; i++) {
			tmp.format("Zeile %d%n", i+1);
		}
		
		tmp.close();
		
		File file = new File("test4.txt");
		FileReader fr = new FileReader(file);
		BufferedReader br = new BufferedReader(fr);
//		BufferedReader br = new BufferedReader(fr, 1024);
		
//		BufferedWriter bw = new BufferedWriter( Writer, int );
		BufferedWriter bw = new BufferedWriter( new FileWriter(new File("test5.txt")) );
		
		String line;
		while((line = br.readLine()) != null){
			System.out.println(line);
			
			bw.write(line);
			bw.newLine(); //Nur Zeilenumbruch
		}
		
		br.close();
		bw.close();
		
		System.out.println("----------------------------------------");
		
		String lineSeparator = System.getProperty("line.separator");
		System.out.println( "lineSeparator.length: " + lineSeparator.length() );
		System.out.println( "lineSeparator(0) == \\r: " + (lineSeparator.charAt(0) =='\r' ) );
		System.out.println( "lineSeparator(1) == \\n: " + (lineSeparator.charAt(1) =='\n' ) );
		
		
	} //end of main

}
